package  
{
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.masks.Pixelmask;
	import net.flashpunk.Sfx;
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class Troy extends Player
	{
		[Embed(source = "img/troy.png" )] private const PLAYER_ANIM:Class;
		
		[Embed(source = "snd/jump2.mp3" )] private const JUMP_MP3:Class;
		private var jumpSfx:Sfx;
	
		public function Troy(px:Number = 305, py:Number = 500) 
		{
			playerAnim = new Spritemap(PLAYER_ANIM, 48, 48);
			playerAnim.add("idle", [0], 10, true);
			playerAnim.add("walking", [1,2,3], 10, true);
			playerAnim.add("jump", [24, 25, 26], 10, true);
			
			
			
			graphic = playerAnim;
			
			setHitbox(30,40);
			
			playerAnim.play("idle");
			
			state = "idle";
			
			jumpSfx = new Sfx(JUMP_MP3);
			
			super(px, py);
		}
		
		
				override public function actualizar():void
		{
		var pressed:Boolean=false;
			
			if ((Input.check(Key.A)) || (Input.check(Key.D)))
			{
					
					if(Input.check((Key.A)))
					{
						flipped = false;
						xSpeed-=power;
						pressed = true;
					}
					else
					{	
						flipped = true;
						xSpeed+=power;
						pressed = true;
					}
					
					if (state != "jump")
						cambiarEstado("walking");
			}
			else if (state != "jump")cambiarEstado("idle");
			
			if (collide("Wall", x, y +jumpPower))
			{
				ySpeed = 0;
				if(state=="jump")
					cambiarEstado("idle");
					
				if (Input.check(Key.W)) {
					jumpSfx.play();
					ySpeed -= jumpPower;
					cambiarEstado("jump");
				}
			} else {
				ySpeed+=gravity;
			}
			
			
			if (Math.abs(xSpeed)<1&&! pressed) {
				xSpeed=0;
			}
			xSpeed*=hFriction;
			ySpeed*=vFriction;
			adjustXPosition();
			adjustYPosition();
			
			
			
			playerAnim.flipped = flipped;
			playerAnim.play(state);
			
		}
		
	}

}